package com.teama4.shop.controller;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.teama4.shop.annotation.NeedLogin;
import com.teama4.shop.annotation.SecurityParameter;
import com.teama4.shop.config.AlipayConfig;
import com.teama4.shop.domain.*;
import com.teama4.shop.service.*;
import com.teama4.shop.utils.AesEncryptUtils;
import com.teama4.shop.utils.JSONUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.security.pkcs11.wrapper.Constants;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @Autowired
    private DeliveryAddressService deliveryAddressService;

    @Autowired
    UserService userService;

    @Autowired
    ServiceService serviceService;

    @Autowired
    CommodityService commodityService;

    @Autowired
    SpecificationService specificationService;

    @Autowired
    CommodityOrdersService commodityOrdersService;
    /**
     *      * 支付完成回调验证操作
     *      * @param response，request
     *      * @throws Exception
     *      * @return void
     *      * @author 有梦想一起实现
     *      
     */
    @RequestMapping("/notify_url")
    public void Notify(HttpServletResponse response, HttpServletRequest request) throws Exception {
        System.out.println("----------------------------notify_url------------------------");
// 商户订单号
        String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "GBK");
// 付款金额
        String total_amount = new String(request.getParameter("total_amount").getBytes("ISO-8859-1"), "GBK");
// 支付宝交易号
        String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"), "GBK");
// 交易说明
        String cus = new String(request.getParameter("body").getBytes("ISO-8859-1"), "GBK");
// 交易状态
        String trade_status = new String(request.getParameter("trade_status").getBytes("ISO-8859-1"), "GBK");
        if (trade_status.equals("TRADE_SUCCESS")) {//支付成功商家操作
            //下面是我写的一个简单的插入操作，根据你的操作自行编写
            Map map = new HashMap();
            map.put("cuId", Integer.valueOf(cus));
//            RepaymentPlan repaymentPlan = new RepaymentPlan();
//            Integer id = Integer.valueOf(out_trade_no);
//            double payablesCheck = Double.valueOf(total_amount);
//            RepaymentPlan repayCheck = serviceMain.selectByPrimaryKey(id);
//            double total = repayCheck.getPayables();
//            if (Double.valueOf(total_amount) < repayCheck.getPayables()) {
//                map.put("ubalance", total - Double.valueOf(total_amount));
//                serviceMain.updateCusMoney(map);
//            }
//            repaymentPlan.setId(id);
//            repaymentPlan.setActualPayment(total);
//            repaymentPlan.setRepaymentStatus(1);
//            int i = serviceMain.updateByPrimaryKeySelective(repaymentPlan);
//            System.out.println("---------------------还款影响行数----------------------------" + i);
        }
    }

    /**
     *      * 同步通知的页面的Controller
     *      * 我这边就简单的返回了一个页面
     *      * @param request，response
     *      * @throws InterruptedException
     *      
     */
    @RequestMapping("/return_url")
    public String Return_url(HttpServletResponse response, HttpServletRequest request) throws InterruptedException {
        HttpSession session = request.getSession();
         String orderId= (String) session.getAttribute("Payorderid");
        Orders orders1 = new Orders();
        orders1.setId(Integer.valueOf(orderId));
        orders1.setOrderStatus(1);//将订单状态改为待收货状态(1)
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd :HH:MM:ss");
        orders1.setPayDate(dateFormat.format(date));
        int res = ordersService.updateByPrimaryKeySelective(orders1);
        if(res>0)
            request.setAttribute("payResult","ok");
        else
            request.setAttribute("payResult","fail");
        return "homeFramework/payOk";
    }


    /**
     * 支付宝支付
     *
     * @param request
     * @param response
     * @throws IOException
     */
    @GetMapping("/aliPay")
    public Object aliPay(HttpServletRequest request, HttpServletResponse response, String orderId, String allPayPrice) throws IOException, AlipayApiException {
        Orders order = ordersService.selectByPrimaryKey(Integer.valueOf(orderId));


        // 获得初始化的AlipayClient
        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);

        // 设置请求参数
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setReturnUrl(AlipayConfig.return_url);
        alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
        //商户订单号，商户网站订单系统中唯一订单号，必填
        String out_trade_no = new String(orderId.getBytes("ISO-8859-1"),"UTF-8");
        //付款金额，必填
        String total_amount = new String(allPayPrice.getBytes("ISO-8859-1"),"UTF-8");
        //订单名称，必填
        String subject = new String(orderId.getBytes("UTF-8"),"UTF-8");
        //商品描述，可空
        String body = new String(order.getOrderDate().getBytes("UTF-8"),"UTF-8");
        HttpSession session = request.getSession();
        session.setAttribute("Payorderid",out_trade_no );
        alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
                + "\"total_amount\":\""+ total_amount +"\","
                + "\"subject\":\""+ subject +"\","
                + "\"body\":\""+ body +"\","
                + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
        // 请求
        String result = alipayClient.pageExecute(alipayRequest).getBody();
        // System.out.println(result);
        AlipayConfig.logResult(result);// 记录支付日志
        response.setContentType("text/html; charset=gbk");
        PrintWriter out = response.getWriter();
        out.print(result);


        return null;
    }


    /**
     * 订单支付方法
     * <p>
     * //     * @param orderId     订单id
     * //     * @param allPayPrice 订单总额
     * //     * @param Rpaypass 支付密码
     */
    @RequestMapping("payNow")
    @SecurityParameter
    @ResponseBody
    @NeedLogin
    public Object PayOrder(HttpServletRequest req, HttpServletResponse resp, Model model, @RequestBody String data) throws Exception {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        Map parse = JSON.parseObject(data, Map.class);
        Integer orderId = (Integer) parse.get("orderId");
        Double allPayPrice = (Double) parse.get("allPayPrice");
        String Rpaypass = (String) parse.get("Rpaypass");

        //收货地址信息
        HttpSession session = req.getSession(false);
        if (session != null && session.getAttribute("userId") != null) {
            Integer userId = (Integer) session.getAttribute("userId");
            if (userId.equals(ordersService.selectByPrimaryKey(orderId).getUserId())) {

                User user1 = userService.selectByPrimaryKey(userId);

                String payPassword = AesEncryptUtils.decrypt(user1.getPayPassword());
                if (Rpaypass.equals(payPassword)) {


                    if (user1.getRemain() >= allPayPrice) {
                        User user = new User();
                        user.setId(userId);
                        user.setRemain(user1.getRemain() - allPayPrice);
                        int i = userService.updateByPrimaryKeySelective(user);
                        if (i > 0) {
                            Orders orders1 = new Orders();
                            orders1.setId(orderId);
                            orders1.setOrderStatus(1);//将订单状态改为待收货状态(1)
                            Date date = new Date();
                            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd :HH:MM:ss");
                            orders1.setPayDate(dateFormat.format(date));
                            int res = ordersService.updateByPrimaryKeySelective(orders1);
                            if (res > 0) {
                                //如果插入成功

                                Map result = new HashMap();
                                result.put("result", "ok");
                                return result;
                            } else {
                                //如果插入失败
                                Map result = new HashMap();
                                result.put("result", "fail");
                                return result;
                            }
                        } else {
                            //如果插入失败
                            Map result = new HashMap();
                            result.put("result", "fail");
                            return result;
                        }
                    } else {

                        Map result = new HashMap();
                        result.put("result", "noMoney");
                        return result;
                    }
                } else {
                    Map result = new HashMap();
                    result.put("result", "payPassError");
                    return result;
                }
            } else {

                Map result = new HashMap();
                result.put("result", "userError");
                return result;
            }
        } else {
            Map result = new HashMap();
            result.put("result", "noSession");
            return result;
        }
    }

    /**
     * 取消订单
     *
     * @param orderId 订单id
     */
    @NeedLogin
    @RequestMapping("cancelOrder")
    public void cancelOrder(HttpServletRequest req, HttpServletResponse resp, Model model, Integer orderId) throws UnsupportedEncodingException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //收货地址信息
        HttpSession session = req.getSession(false);
        if (session != null && session.getAttribute("userId") != null) {
            Integer userId = (Integer) session.getAttribute("userId");
            if (userId.equals(ordersService.selectByPrimaryKey(orderId).getUserId())) {

                Orders orders = new Orders();
                orders.setId(orderId);
                orders.setOrderStatus(5);//将订单状态改为取消状态(5)

                int res = ordersService.updateByPrimaryKeySelective(orders);
                if (res > 0) {
                    //如果插入成功
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put("result", "ok");
                    JSONUtil.printByJSON(resp, map);
                } else {
                    //如果插入失败
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put("result", "fail");
                    JSONUtil.printByJSON(resp, map);
                }
            } else {
                //如果session获取不到值
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("result", "userError");
                JSONUtil.printByJSON(resp, map);
            }
        } else {
            //如果session获取不到值
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("result", "noSession");
            JSONUtil.printByJSON(resp, map);
        }
    }
    /**
     * 确认收货
     *
     * @param orderId 订单id
     */
    @NeedLogin
    @RequestMapping("orderOk")
    public void orderOk(HttpServletRequest req, HttpServletResponse resp, Model model, Integer orderId) throws UnsupportedEncodingException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //收货地址信息
        HttpSession session = req.getSession(false);
        if (session != null && session.getAttribute("userId") != null) {
            Integer userId = (Integer) session.getAttribute("userId");
            if (userId.equals(ordersService.selectByPrimaryKey(orderId).getUserId())) {

                Orders orders = new Orders();
                orders.setId(orderId);
                orders.setOrderStatus(3);//将订单状态改为取消状态(5)

                int res = ordersService.updateByPrimaryKeySelective(orders);
                if (res > 0) {
                    //如果插入成功
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put("result", "ok");
                    JSONUtil.printByJSON(resp, map);
                } else {
                    //如果插入失败
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put("result", "fail");
                    JSONUtil.printByJSON(resp, map);
                }
            } else {
                //如果session获取不到值
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("result", "userError");
                JSONUtil.printByJSON(resp, map);
            }
        } else {
            //如果session获取不到值
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("result", "noSession");
            JSONUtil.printByJSON(resp, map);
        }
    }
    /**
     * 查询订单是否已经申请售后
     *
     * @param req
     * @param resp
     * @param model
     * @param orderId
     * @throws UnsupportedEncodingException
     */
    @NeedLogin
    @RequestMapping("orderIsInService")
    public void orderIsInService(HttpServletRequest req, HttpServletResponse resp, Model model, Integer orderId) throws UnsupportedEncodingException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //收货地址信息
        HttpSession session = req.getSession(false);
        if (session != null && session.getAttribute("userId") != null) {
            Integer userId = (Integer) session.getAttribute("userId");
            if (userId.equals(ordersService.selectByPrimaryKey(orderId).getUserId())) {
                Orders order = ordersService.selectByPrimaryKey(orderId);
                if (order.getServiceId() == null || order.getServiceId().equals("")) {

                    HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put("result", "unExist");
                    JSONUtil.printByJSON(resp, map);

                } else {
                    Service service = serviceService.selectByPrimaryKey(order.getServiceId());
                    if (service.getServiceStatus() == 3) {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("result", "unExist");
                        JSONUtil.printByJSON(resp, map);
                    } else {
                        Orders orders = new Orders();
                        orders.setId(orderId);
                        orders.setOrderStatus(4);//将订单状态改为售后状态(4)
                        int res1 = ordersService.updateByPrimaryKeySelective(orders);
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("result", "exist");
                        JSONUtil.printByJSON(resp, map);
                    }
                }
            } else {
                //如果session获取不到值
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("result", "userError");
                JSONUtil.printByJSON(resp, map);
            }
        } else {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("result", "noSession");
            JSONUtil.printByJSON(resp, map);
        }
    }

    /**
     * 退款
     *
     * @param orderId     订单id
     * @param applyReason 退款原因
     */
    @NeedLogin
    @RequestMapping("refund")
    public void refund(HttpServletRequest req, HttpServletResponse resp, Model model, Integer orderId, String applyReason) throws UnsupportedEncodingException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //收货地址信息
        HttpSession session = req.getSession(false);
        if (session != null && session.getAttribute("userId") != null) {
            Integer userId = (Integer) session.getAttribute("userId");
            if (userId.equals(ordersService.selectByPrimaryKey(orderId).getUserId())) {
                OrdersComSpeAddress order = ordersService.selectAllOrdersByKey(orderId);


                Integer orderStatus = order.getOrderStatus();
                if (orderStatus == 0 || orderStatus == 1 || orderStatus == 2 || orderStatus == 3) {

                    if (serviceService.selectByPrimaryKey(order.getServiceId()) != null) {
                        serviceService.deleteByPrimaryKey(order.getServiceId());
                    }
                    //将订单添加到售后表中
                    Integer serviceId = UUID.randomUUID().toString().hashCode();
                    if (serviceId < 0) {//有可能是负数
                        serviceId = -serviceId;
                    }
                    Service service = new Service();
                    service.setId(serviceId);
                    service.setUserId(userId);
                    service.setOrderStatus(orderStatus);
                    service.setServiceStatus(0);//设置为提交未处理状态
                    service.setReadStatus(0);//设置为未读状态
                    Date date1 = new Date();
                    SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd :HH:MM:ss");
                    service.setApplyTime(dateFormat1.format(date1));

                    service.setApplyReason("reason:退款,userReason:" + applyReason);
                    int insertSelective = serviceService.insertSelective(service);

                    CommodityOrdersExample commodityOrdersExample = new CommodityOrdersExample();
                    commodityOrdersExample.createCriteria().andOrdersIdEqualTo(orderId);

                    List<CommodityOrders> commodityOrders = commodityOrdersService.selectByExample(commodityOrdersExample);
                    for(CommodityOrders cos : commodityOrders){
                        Specification specification = new Specification();
                        specification.setId(cos.getSpecificationId());
                        if (specificationService.selectByPrimaryKey(cos.getSpecificationId()).getInventory()!=null)
                        specification.setInventory(specificationService.selectByPrimaryKey(cos.getSpecificationId()).getInventory()+1);
                        specificationService.updateByPrimaryKeySelective(specification);
                    }

                    if (insertSelective > 0) {
                        //将订单状态改为4
                        Orders orders = new Orders();
                        orders.setId(orderId);
                        orders.setServiceId(serviceId);
                        orders.setOrderStatus(4);//将订单状态改为售后状态(4)
                        int res1 = ordersService.updateByPrimaryKeySelective(orders);
                        if (res1 > 0) {
//                            //加用户余额
//                            User user = new User();
//                            user.setId(userId);
//                            user.setRemain(userService.selectByPrimaryKey(userId).getRemain() + order.getSumPrice());
//                            int res2 = userService.updateByPrimaryKeySelective(user);
//                            if (res2 > 0) {
                            HashMap<String, Object> map = new HashMap<String, Object>();
                            map.put("result", "ok");
                            JSONUtil.printByJSON(resp, map);
//                            } else {
//                                HashMap<String, Object> map = new HashMap<String, Object>();
//                                map.put("result", "addUserRemainfail");
//                                JSONUtil.printByJSON(resp, map);
//                            }


                        } else {
                            HashMap<String, Object> map = new HashMap<String, Object>();
                            map.put("result", "changeOrderStatusfail");
                            JSONUtil.printByJSON(resp, map);
                        }
                    } else {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("result", "insServicefail");
                        JSONUtil.printByJSON(resp, map);
                    }

                } else {
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put("result", "orderStatusError");
                    JSONUtil.printByJSON(resp, map);
                }

            } else {
                //如果session获取不到值
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("result", "userError");
                JSONUtil.printByJSON(resp, map);
            }
        } else {
            //如果session获取不到值
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("result", "noSession");
            JSONUtil.printByJSON(resp, map);
        }
    }

    /**
     * 删除订单
     *
     * @param orderId 订单id
     */
    @NeedLogin
    @RequestMapping("delOrder")
    public void delOrder(HttpServletRequest req, HttpServletResponse resp, Model model, Integer orderId) throws UnsupportedEncodingException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //收货地址信息
        HttpSession session = req.getSession(false);
        if (session != null && session.getAttribute("userId") != null) {
            Integer userId = (Integer) session.getAttribute("userId");
            if (userId.equals(ordersService.selectByPrimaryKey(orderId).getUserId())) {

                Orders orders = new Orders();
                orders.setId(orderId);
                orders.setOrderStatus(6);//将订单状态改为取消状态(5)

                int res = ordersService.updateByPrimaryKeySelective(orders);
                if (res > 0) {
                    //如果插入成功
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put("result", "ok");
                    JSONUtil.printByJSON(resp, map);
                } else {
                    //如果插入失败
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put("result", "fail");
                    JSONUtil.printByJSON(resp, map);
                }
            } else {
                //如果session获取不到值
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("result", "userError");
                JSONUtil.printByJSON(resp, map);
            }
        } else {
            //如果session获取不到值
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("result", "noSession");
            JSONUtil.printByJSON(resp, map);
        }
    }

    /**
     * 撤销售后申请
     *
     * @param orderId 订单id
     */
    @NeedLogin
    @RequestMapping("undoService")
    public void undoService(HttpServletRequest req, HttpServletResponse resp, Model model, Integer orderId) throws UnsupportedEncodingException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //收货地址信息
        HttpSession session = req.getSession(false);
        if (session != null && session.getAttribute("userId") != null) {
            Integer userId = (Integer) session.getAttribute("userId");
            if (userId.equals(ordersService.selectByPrimaryKey(orderId).getUserId())) {

                Orders order = ordersService.selectByPrimaryKey(orderId);
                Integer serviceId = order.getServiceId();
                Service service = serviceService.selectByPrimaryKey(serviceId);

                Orders o = new Orders();
                o.setId(orderId);
                o.setOrderStatus(service.getOrderStatus());//将订单状态改为原来的状态

                int res1 = ordersService.updateByPrimaryKeySelective(o);
                if (res1 > 0) {
                    service.setServiceStatus(3);//将售后表改为已撤销状态(3)
                    int res = serviceService.updateByPrimaryKeySelective(service);
                    if (res > 0) {
                        //如果插入成功
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("result", "ok");
                        JSONUtil.printByJSON(resp, map);
                    } else {
                        //如果插入失败
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("result", "fail");
                        JSONUtil.printByJSON(resp, map);
                    }
                } else {
                    //如果插入失败
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put("result", "fail");
                    JSONUtil.printByJSON(resp, map);
                }
            } else {
                //如果session获取不到值
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("result", "userError");
                JSONUtil.printByJSON(resp, map);
            }
        } else {
            //如果session获取不到值
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("result", "noSession");
            JSONUtil.printByJSON(resp, map);
        }
    }

    /**
     * 查看售后结果
     *
     * @param orderId 订单id
     */
    @NeedLogin
    @RequestMapping("lookServiceResult")
    public void lookServiceResult(HttpServletRequest req, HttpServletResponse resp, Model model, Integer orderId) throws UnsupportedEncodingException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //收货地址信息
        HttpSession session = req.getSession(false);
        if (session != null && session.getAttribute("userId") != null) {
            Integer userId = (Integer) session.getAttribute("userId");
            if (userId.equals(ordersService.selectByPrimaryKey(orderId).getUserId())) {

                Orders order = ordersService.selectByPrimaryKey(orderId);
                Integer serviceId = order.getServiceId();
                Service service = serviceService.selectByPrimaryKey(serviceId);
                //如果订单状态为已经处理结束
                if (service.getServiceStatus().equals(2)) {
                    //如果处理结果不为空
                    if (StringUtils.isNotBlank(service.getResult())) {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("result", "ok");
                        map.put("res", service.getResult());
                        JSONUtil.printByJSON(resp, map);
                    } else {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("result", "noResult");
                        JSONUtil.printByJSON(resp, map);
                    }

                } else {
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put("result", "notok");
                    JSONUtil.printByJSON(resp, map);
                }

            } else {
                //如果session获取不到值
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("result", "userError");
                JSONUtil.printByJSON(resp, map);
            }
        } else {
            //如果session获取不到值
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("result", "noSession");
            JSONUtil.printByJSON(resp, map);
        }
    }


}
